]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
keyboard: Add proper tracking of window movements to focus tracker
authorJonas Dreßler <verdre@v0yd.nl>
Fri, 26 Feb 2021 15:08:20 +0000 (16:08 +0100)
committerMarge Bot <marge-bot@gnome.org>
Sat, 13 Mar 2021 18:28:15 +0000 (18:28 +0000)
So far the FocusTracker of the OSK can only recognize grab ops on a
window, that is when the user grabs the window using a mouse or the
touchscreen and actively drags it somewhere.

Window can also be moved using keyboard shortcuts, fullscreen buttons or
other ways which don't rely on grabs. Start also supporting those window
movements by listening to the "position-changed" signal on the currently
focused window and emitting the new "window-moved" signal in that case.

Because the OSK sometimes moves windows by itself, we temporarily
disconnect from that new signal while we move the focused window in
_windowSlideAnimationComplete().

This also takes care of resetting this._focusWindowStartY on movements
of the window.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1760>

js/ui/keyboard.js

index cc922c28567242151c1aa0b511936f6efeab5138..ce4f11fab42623a1b3664fdc5bb57fd95f61ce62 100644 (file)
@@ -592,6 +592,11 @@ var FocusTracker = class {
     }
 
     destroy() {
+        if (this._currentWindow) {
+            this._currentWindow.disconnect(this._currentWindowPositionChangedId);
+            delete this._currentWindowPositionChangedId;
+        }
+
         global.display.disconnect(this._notifyFocusId);
         global.display.disconnect(this._grabOpBeginId);
         Main.inputMethod.disconnect(this._cursorLocationChangedId);
@@ -605,7 +610,18 @@ var FocusTracker = class {
     }
 
     _setCurrentWindow(window) {
+        if (this._currentWindow) {
+            this._currentWindow.disconnect(this._currentWindowPositionChangedId);
+            delete this._currentWindowPositionChangedId;
+        }
+
         this._currentWindow = window;
+
+        if (this._currentWindow) {
+            this._currentWindowPositionChangedId =
+                this._currentWindow.connect('position-changed', () =>
+                    this.emit('window-moved'));
+        }
     }
 
     _setCurrentRect(rect) {
@@ -1275,13 +1291,12 @@ var Keyboard = GObject.registerClass({
         this._focusTracker = new FocusTracker();
         this._connectSignal(this._focusTracker, 'position-changed',
             this._onFocusPositionChanged.bind(this));
-        this._connectSignal(this._focusTracker, 'window-grabbed', () => {
-            // Don't use _setFocusWindow() here because that would move the
-            // window while the user has grabbed it. Instead we simply "let go"
-            // of the window.
-            this._focusWindow = null;
-            this._focusWindowStartY = null;
-        });
+        this._connectSignal(this._focusTracker, 'window-grabbed',
+            this._onFocusWindowMoving.bind(this));
+
+        this._windowMovedId = this._focusTracker.connect('window-moved',
+            this._onFocusWindowMoving.bind(this));
+
         // Valid only for X11
         if (!Meta.is_wayland_compositor()) {
             this._connectSignal(this._focusTracker, 'focus-changed', (_tracker, focused) => {
@@ -1328,6 +1343,11 @@ var Keyboard = GObject.registerClass({
     }
 
     _onDestroy() {
+        if (this._windowMovedId) {
+            this._focusTracker.disconnect(this._windowMovedId);
+            delete this._windowMovedId;
+        }
+
         if (this._focusTracker) {
             this._focusTracker.destroy();
             delete this._focusTracker;
@@ -1934,7 +1954,11 @@ var Keyboard = GObject.registerClass({
         finalY += frameRect.y - bufferRect.y;
 
         frameRect.y = finalY;
+
+        this._focusTracker.disconnect(this._windowMovedId);
         window.move_frame(true, frameRect.x, frameRect.y);
+        this._windowMovedId = this._focusTracker.connect('window-moved',
+            this._onFocusWindowMoving.bind(this));
     }
 
     _animateWindow(window, show) {
@@ -1957,6 +1981,18 @@ var Keyboard = GObject.registerClass({
         });
     }
 
+    _onFocusWindowMoving() {
+        if (this._focusTracker.currentWindow === this._focusWindow) {
+            // Don't use _setFocusWindow() here because that would move the
+            // window while the user has grabbed it. Instead we simply "let go"
+            // of the window.
+            this._focusWindow = null;
+            this._focusWindowStartY = null;
+        }
+
+        this.close(true);
+    }
+
     _setFocusWindow(window) {
         if (this._focusWindow === window)
             return;